<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="detailList" >
      <el-table-column label="编号" width="100" type="index" align="center" fixed="left"
                       :index="index=>index+1"/>
      <el-table-column label="配菜名称" prop="resourceName" align="center" width="120"/>
      <el-table-column label="检测结果" prop="status" align="center" width="160">
        <template #default="scope">
          <span v-show="!scope.row.editFlag" :style="{'color': statusColors(scope.row.status)}">{{scope.row.status}}</span>
          <el-select v-show="scope.row.editFlag" v-model="scope.row.status" placeholder="请选择" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in statusOptions" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="检测内容" prop="content" align="center" width="200"/>
      <el-table-column label="快速检测农药残留" align="center" width="200">
        0
      </el-table-column>
      <el-table-column label="非食物物质" align="center" width="200">
        0
      </el-table-column>
      <el-table-column label="易滥用食品添加剂" align="center" width="200">
        0
      </el-table-column>
      <el-table-column label="重金属" align="center" width="200">
        0
      </el-table-column>
      <el-table-column label="创建人" prop="createBy"  width="120" align="center"/>
      <el-table-column label="修改人" prop="updateBy" width="120" align="center"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间"  align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="160">
        <template #default="scope">
          <div style="">
            <el-button size="small"
                       type="text"
                       icon="CircleCheck"
                       v-show="scope.row.editFlag"
                       @click="submit(scope.row, $index)">保存
            </el-button>
            <el-button size="small"
                       type="text"
                       icon="CircleClose"
                       v-show="scope.row.editFlag"
                       @click="cancel(scope.row, $index)">取消
            </el-button>
            <el-button size="small"
                       icon="Edit"
                       type="text"
                       v-show="!scope.row.editFlag"
                       @click="edit(scope.row, $index)">编辑
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { listAll, get, update} from "@/api/examine/in/detail";
  export default {
    name: "StoreInExamineDetail",
    dicts: [],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        detailList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        form: {},
        statusOptions: [{
          label: "检测中",
          value: "检测中"
        },{
          label: "检测通过",
          value: "检测通过"
        },{
          label: "检测不通过",
          value: "检测不通过"
        }],
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        // 表单校验
        rules: {},
      };
    },
    created() {
      this.id = this.$route.params && this.$route.params.id;
      this.getList();
    },
    methods: {
      statusColors(status) {
        if (status === "检测通过") {
          return '#2a9c4a'
        } else if (status === "检测不通过") {
          return '#FF0000'
        } else {
          return '#fe9f29'
        }
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        listAll({
          examineId: this.id,
        }).then(response => {
            this.detailList = response.rows;
            this.loading = false;
          }
        );
      },
      submit: function(row, index) {
        let updateData = {
          id: row.id,
          amount: row.amount,
          status: row.status,
        }
        update(updateData).then(res => {
          this.$modal.msgSuccess("更新成功");
          row.editFlag = false;
          this.getList();
        })
      },
      cancel: function(row, index) {
        row.editFlag = false;
        this.getList();
      },
      edit: function(row, index) {
        row.editFlag = true;
        this.$set(this.detailList, index, row);
      },
    }
  };
</script>
